<?php
	class sess_session
	{
	 	private $_key	=	''; 	
	 	
	 	public function __construct()
	 	{
	 		// Start the session
	 		session_start();
	 		
			if( !isset( $_SESSION['key'] ) )
			{	
				$this->_key =  md5( uniqid( mt_rand(), true ) );
				$_SESSION['key'] = $this->_key;
			}
			else
			{
				$this->_key = $_SESSION['key'];
			}
			
			// Prevent false sessions
			if( !isset( $this->__user ) )
			{
				// hash the IP address
				$this->__user = md5($_SERVER['REMOTE_ADDR']);
			}
			elseif( $this->__user != md5( $_SERVER['REMOTE_ADDR'] ) )
			{
				// Prevent the user from doing anything [E_FATAL]
				trigger_error( 'NGen::Session -> Invalid session', E_USER_ERROR );
			}
			
			// Prevention for session fixation
			session_regenerate_id(true);
		}
	 			 			
		public function __get( $name )
		{
			if( $this->__isset( $name ) )
			{
				return $_SESSION[$this->_key . $name];
			}
		}
				
		public function __set( $name, $value )
		{
			$_SESSION[$this->_key . $name] = $value;
		}
		
		public function __isset( $name )
		{
			if( isset( $_SESSION[$this->_key . $name] ) )
			{
				return true;
			}
			
			return false;
		}
								
		public function del( )
		{
			foreach( func_get_args() as $ret )
			{
				unset($_SESSION[$this->_key . $ret]);
			}
		 	
		 	return;
		}
	}
?>